package com.niit.shopsys.stub;

import com.niit.shopsys.InventorySystem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

// 库存系统测试桩
public class InventorySystemStub implements InventorySystem {
    private boolean stockStatus;
    private boolean reservationSuccess;
    private List<Map<String, Object>> checkCalls = new ArrayList<>();
    private List<Map<String, Object>> reserveCalls = new ArrayList<>();

    public InventorySystemStub(boolean stockStatus, boolean reservationSuccess) {
        this.stockStatus = stockStatus;
        this.reservationSuccess = reservationSuccess;
    }

    @Override
    public boolean checkStock(String productId, int quantity) {
        Map<String, Object> call = new HashMap<>();
        call.put("productId", productId);
        call.put("quantity", quantity);
        checkCalls.add(call);
        return stockStatus;
    }

    @Override
    public boolean reserveStock(String productId, int quantity, String orderId) {
        Map<String, Object> call = new HashMap<>();
        call.put("productId", productId);
        call.put("quantity", quantity);
        call.put("orderId", orderId);
        reserveCalls.add(call);
        return reservationSuccess;
    }

    public List<Map<String, Object>> getCheckCalls() { return checkCalls; }
    public List<Map<String, Object>> getReserveCalls() { return reserveCalls; }
}
